package com.md.infrastructure.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.md.config.database.MyMetaObjectHandler;
import com.md.value.constants.DefaultServerContext;
import com.md.value.server.ServerContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnClass(value = {MybatisPlusInterceptor.class})
@Primary
public class CustomMetaObjectHandler extends MyMetaObjectHandler {

  @Override
  public void insertFill(final MetaObject metaObject) {
    super.insertFill(metaObject);  // 调用父类的方法
    metaObject.setValue("tenantId", ServerContext.get(DefaultServerContext.TENANT_ID));
    metaObject.setValue("brandId", ServerContext.get(DefaultServerContext.BRAND_ID));
  }

  @Override
  public void updateFill(final MetaObject metaObject) {
    super.updateFill(metaObject);  // 调用父类的方法
  }
}
